﻿
using System.ComponentModel;
using System;

namespace MediaBrowserSL.RIA.MediaBrowserServiceReference
{
    /// <summary>
    /// User Extension
    /// </summary>
    public partial class User : IDataErrorInfo
    {
        #region Private member
        private bool existLogin;
        private String error;
        #endregion
        
        #region Public properties
        public bool ExistLogin
        {
            get { return existLogin; }
            set
            {
                existLogin = value;
            }

        }
        #endregion

        #region IDataErrorInfo
        public string Error
        {
            get { return error; }

        }
        public string this[string columnName]
        {
            get
            {
                error = null;

                if (columnName == "FirstName")
                {
                    if ((FirstName != null) && (FirstName.Equals("")))
                        error = "Le Nom est un champ obligatoire";
                }
                else if (columnName == "LastName")
                {
                    if ((LastName != null) && (LastName.Equals("")))
                        error = "Le Prénom est un champ obligatoire";
                }
                else if (columnName == "Login")
                {
                    if ((Login != null) && (Login.Equals("")))
                        error = "L'identifiant est un champ obligatoire";

                    if (ExistLogin)
                        error = "Cet identifiant exist déjà";
                }
                else if (columnName == "Password")
                {
                    if ((Password != null) && (Password.Equals("")))
                        error = "Le mot de passe est un champ obligatoire";

                }

                return error;
            }
        }
        #endregion

        #region Public Methods
        public bool ValidData()
        {
            bool result = true;

            if ((String.IsNullOrEmpty(FirstName)) || (String.IsNullOrEmpty(LastName)) || (String.IsNullOrEmpty(Login)) || (String.IsNullOrEmpty(Password)) ||
                (Login.Trim().Length < 8) || (Password.Trim().Length < 10) || ExistLogin)
                result = false;

            return result;

        }
        #endregion
    }
}
